﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using ARC.API.ExternalInterface.Models;
using Micro.Core.FrameWork.Validate;
using Micro.SMSGatWay.Core.Model.Req.APIModel;
using Micro.SMSGatWay.Core.Model.Resp.ApiModel;
using Micro.SMSGatWay.Core.Repository;
using Micro.SMSGatWay.Core.Service;

namespace Micro.SMSGatWay.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SmsController : ControllerBase
    {
        private readonly ISmsApiService _smsApiService;
        public SmsController(ISmsApiService smsApiService)
        {
            _smsApiService = smsApiService;
        }
        /// <summary>
        /// 发送单条短信
        /// </summary>
        /// <param name="reqSmsSend"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<RespSmsApiResponse> SendSms([FromQuery] ReqSmsSend reqSmsSend)
        {
            if (!ValidateHelper.IsMobile(reqSmsSend.Phone))
                return new RespSmsApiResponse() { Code = Status.Error, Msg = "手机号验证失败" };
            if ((int)reqSmsSend.ProviderType > 1)
                return new RespSmsApiResponse() { Code = Status.Error, Msg = "没有此服务商" };

            return await _smsApiService.SendSms(reqSmsSend);
        }
    }
}
